package Hxw3DEngine.core.materials.shader 
{

	import flash.utils.Dictionary;
	import Hxw3DEngine.core.materials.shader.utils.ShaderRegisterCache;
	import Hxw3DEngine.core.materials.shader.utils.ShaderRegisterElement;
	import Hxw3DEngine.proxy.Stage3DProxy;
	import Hxw3DEngine.utils.Stage3dUtils;
	/**
	 * ...
	 * @author huangxw   封装汇编的方法
	 */
	public class ShaderProgram 
	{
		private static const vertex:int = 1;
		
		private static const fragment:int = 2;
		
		private var resultCode:String = "";
		
		//shader代码字典
		private var codeDic:Dictionary = new Dictionary();
		
		public function get code():String {
			return codeDic[status];
		}
		
		public function set code(val:String):void {
			codeDic[status] = val;	
		}
		
		
		//包含注释的shader代码给自己看的
		private var desDic:Dictionary = new Dictionary();
		
		public function get des():String {
			return desDic[status];
		}
		
		public function set des(val:String):void {
			desDic[status] = val;
		}
		
		//当前状态
		private var _status:int = vertex;
		public function set status(value:int):void{
			_status = value;
		}
		
		public function get status():int{
			return _status;
		}
		
		//创建片断代码
		public function getFragmentCode(regCache : ShaderRegisterCache) : String {
			status = fragment;
			code = "";
			des = "";
			return "";
		}
		
		//创建顶点代码
		public function getVertexCode(regCache : ShaderRegisterCache) : String {
			status = vertex;
			code = "";
			des = "";
			return "";
		}
		
		//---------------------------普通------------------------------------------
		public function mov(to:Object, from:Object):void {
			resultCode = "\nmov " + to + ", " + from; 
			code += resultCode;
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(to, from);
			des += resultCode;
		}
		
		//---------------------------向量运算---------------------------------------
		public function nrm(to:Object, from:Object):void {
			resultCode = "\nnrm " + to + ", " + from; 
			code += resultCode;
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(to, from);
			des += resultCode;
		}
		
		//----------------------------矩阵运算--------------------------------------
		public function m33(result:Object, param0:Object, param1:Object):void {
			resultCode = "\nm33 " + result + ", " + param0 + ", " + param1; 
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1);
			des += resultCode;
		}
		
		public function m44(result:Object, param0:Object, param1:Object):void {
			resultCode =  "\nm44 " + result + ", " + param0 + ", " + param1; 
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1);
			des += resultCode;
		}
		
		public function mul(result:Object, param0:Object, param1:Object):void {
			resultCode = "\nmul " + result + ", " + param0 + ", " + param1;  
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1);
			des += resultCode;
		}
		
		public function tex(result:Object, param0:Object, param1:Object, param2:Object):void {
			resultCode = "\ntex " + result + ", " + param0 + ", " + param1 + param2; 
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1,param2);
			des += resultCode;
		}
		
		public function add(result:Object, param0:Object, param1:Object):void {
			resultCode = "\nadd " + result + ", " + param0 + ", " + param1; 
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1);
			des += resultCode;
		}
		
		public function dp3(result:Object, param0:Object, param1:Object):void {
			resultCode = "\ndp3 " + result + ", " + param0 + ", " + param1;  
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1);
			des += resultCode;
		}
		
		public function sqt(result:Object, param0:Object):void {
			resultCode = "\nsqt " + result + ", " + param0;
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0);
			des += resultCode;
		}
		
		public function sub(result:Object, param0:Object, param1:Object):void {
			resultCode = "\nsub " + result + ", " + param0 + ", " + param1; 	
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1);
			des += resultCode;
		}
		
		public function max(result:Object, param0:Object, param1:Object):void {
			resultCode ="\nmax " + result + ", " + param0 + ", " + param1; 	
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1);
			des += resultCode;
		}
		
		
		public function pow(result:Object, param0:Object, param1:Object):void {
			resultCode ="\npow " + result + ", " + param0 + ", " + param1; 	
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1);
			des += resultCode;
		}
		
		
		public function neg(result:Object, param0:Object):void {
			resultCode =  "\nneg " + result + ", " + param0; 	
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0);
			des += resultCode;
		}
		
		public function exp(result:Object, param0:Object):void {
			resultCode = "\nexp " + result + ", " + param0; 	
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0);
			des += resultCode;
		}
		
		public function dp4(result:Object, param0:Object, param1:Object):void {
			resultCode = "\ndp4 " + result + ", " + param0 + ", " + param1; 	
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1);
			des += resultCode;
		}
		
		public function rsq(result:Object, param0:Object):void {
			resultCode = "\nrsq " + result + ", " + param0; 	
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0);
			des += resultCode;
		}
		
		public function crs(result:Object, param0:Object, param1:Object):void {
			resultCode = "\ncrs " + result + ", " + param0 + ", " + param1; 	
			code += resultCode
			if (!Stage3DProxy.debug) return ;
			des += Stage3dUtils.BuildDes(result, param0,param1);
			des += resultCode;
		}
		
		
	}

}